package com.ai5suoai.ams.service;

import com.ai5suoai.ams.entity.IToVo;
import com.ai5suoai.ams.web.vo.ToEntity;

import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.io.Serializable;
import java.util.List;

/**
 * @author chenzhenjia
 * @since 16/4/21
 */
public abstract class MongoService<T extends IToVo<VO>, VO extends ToEntity<T>, ID extends
        Serializable> extends AbstractService<T, VO, ID> {

    abstract MongoRepository<T, ID> getRepository();

    public List<T> findAll(Sort sort) {
        return getRepository().findAll(sort);
    }

    public List<T> findAll() {
        return getRepository().findAll();
    }

    public <S extends T> S insert(S entity) {
        return getRepository().insert(entity);
    }

    public <S extends T> List<S> insert(Iterable<S> entities) {
        return getRepository().insert(entities);
    }

    public <S extends T> List<S> save(Iterable<S> entites) {
        return getRepository().save(entites);
    }
}
